using ValidationFramework.Extensions;
using ValidationFramework.Configuration.Xml;
using ValidationFramework.Configuration;

namespace ValidationFramework.Specifications
{
    /// <summary>
    /// A <see cref="IRuleConfigReader"/> that creates a <see cref="ValidatableRule"/> from a <see cref="RuleData"/>.
    /// </summary>
    /// <example>
    /// <code lang="xml" title="This example shows an xml configuration for ValidatableRuleConfigReader.">
    /// <rule 
    /// errorMessage="hello" 
    /// typeName="ValidatableRule"/>
    /// </code>
    /// </example>
    /// <seealso cref="ValidatableRule"/>
    /// <seealso cref="ConfigurationService"/>
    public sealed class IsValidParser : ISpecificationXmlParser
    {
        // --- Methods
        public ISpecification GetSpecification(System.Xml.XmlElement SpecificationElement, RuleContext member)
        {
            return new IsValidSpec()
            {
                UseTargetErrorMessages = SpecificationElement.GetAttribute("useTargetErrorMessages", false),
                TargetRuleSet = SpecificationElement.GetAttribute<string>("targetRuleSet", "")
            };
        }
    }
}